﻿Imports System.Data.OleDb

Public Class AddNewRestaurant
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Submit.Click

        If fup_RestaurantPicture.HasFile Then
            fup_RestaurantPicture.SaveAs(Server.MapPath("pictures") & "/" & fup_RestaurantPicture.FileName)
        End If




        Dim sql As String = "INSERT INTO Restaurants (RestaurantName,Postcode,Website,RestaurantPicture,AveragePrice,PhoneNumber,MichelinStars) VALUES (@f1,@f2,@f3,f4,@f5,@f6,@f7)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", tb_RestaurantName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_Postcode.Text)
        cmd.Parameters.AddWithValue("@f3", tb_Website.Text)
        cmd.Parameters.AddWithValue("@f4", "pictures/" & fup_RestaurantPicture.FileName)
        cmd.Parameters.AddWithValue("@f5", tb_AveragePrice.Text)
        cmd.Parameters.AddWithValue("@f6", tb_PhoneNumber.Text)
        cmd.Parameters.AddWithValue("@f7", rbl_MichelinStars.SelectedValue)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Response.Redirect("Restaurantlist.aspx")


    End Sub
End Class